package com.lingying.caiwudailikehudaun.controller.gonShangNianJian;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lingying.caiwudailikehudaun.dto.tuPianXinXi.TuPianXinXiDTO;
import com.lingying.caiwudailikehudaun.mapper.gongShangNianJian.GongShangNianJianMapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/gongShangNianJian")
public class GongShangNianJianController {

    @Resource
    HttpServletRequest httpServletRequest;

    @Resource
    GongShangNianJianMapper gongShangNianJianMapper;

    /**
     * 张聚源 2021-05-10
     * 添加工商年检
     * @param
     * @param
     * @param
     * @return
     */
    @RequestMapping(value = "/selectGongShangNianJian", method = RequestMethod.GET)
    public Object selectGongShangNianJian(
            @RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
            @RequestParam(value = "limit", defaultValue = "10", required = false) Integer limit,
            @RequestParam(value = "companyName", required = false) String companyName,
            @RequestParam(value = "suoShuNainDu",required = false) String suoShuNainDu,
            @RequestParam(value = "KeHuLeiXing",required = false) Integer KeHuLeiXing,
            @RequestParam(value = "fuWuZhuangTai",required = false) Integer fuWuZhuangTai

    ) {

        JSONObject object = new JSONObject();
        System.out.println(suoShuNainDu);
        System.out.println();
        Integer pages = (page - 1) * limit;
        Integer zuoZhangShenBaoId = (Integer) httpServletRequest.getSession().getAttribute("zuoZhangShenBaoId");
        List<Map<String, Object>> selectYiNianJian =null;
        Integer count =0;
        if (KeHuLeiXing == null||KeHuLeiXing == 0) {
            selectYiNianJian = gongShangNianJianMapper.selectGongShangNianJian(zuoZhangShenBaoId, companyName, suoShuNainDu, pages, limit);
            count = gongShangNianJianMapper.selectYiGongShangNianJiancount(zuoZhangShenBaoId, companyName, suoShuNainDu);
        }else{
//                未年检
            selectYiNianJian = gongShangNianJianMapper.selectWeiNianJian(zuoZhangShenBaoId,companyName,fuWuZhuangTai,pages,limit);
            count = gongShangNianJianMapper.selectWeiGongShangNianJiancount(zuoZhangShenBaoId,companyName,fuWuZhuangTai);
        }
        if (selectYiNianJian!=null) {
            object.put("code", 0);
            object.put("msg", "查询成功");
            object.put("data", selectYiNianJian);
            object.put("count",count);
        } else {
            object.put("code", 500);
            object.put("msg", "查询失败");
        }
        return object;
    }
}
